home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual BASIC 5.0 (Ent. Edition) / Vb5ent Extractor.EXE / VB / SAMPLES / COMPTOOL / ADDINS / TABORDER / TABORDER.DOB (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-10-29  |  14.3 KB  |  439 lines

  1. VERSION 5.00
  2. Begin VB.UserDocument docTabOrder 
  3.    ClientHeight    =   660
  4.    ClientLeft      =   4110
  5.    ClientTop       =   3195
  6.    ClientWidth     =   2085
  7.    HScrollSmallChange=   225
  8.    KeyPreview      =   -1  'True
  9.    LockControls    =   -1  'True
  10.    ScaleHeight     =   660
  11.    ScaleWidth      =   2085
  12.    Tag             =   "10"
  13.    VScrollSmallChange=   225
  14.    Begin VB.CommandButton cmdRefresh 
  15.       Height          =   330
  16.       Left            =   1365
  17.       Picture         =   "TabOrder.dox":0000
  18.       Style           =   1  'Graphical
  19.       TabIndex        =   5
  20.       Top             =   15
  21.       UseMaskColor    =   -1  'True
  22.       Width           =   330
  23.    End
  24.    Begin VB.CommandButton cmdLeftToRight 
  25.       Height          =   330
  26.       Left            =   1035
  27.       Picture         =   "TabOrder.dox":0102
  28.       Style           =   1  'Graphical
  29.       TabIndex        =   4
  30.       ToolTipText     =   "102"
  31.       Top             =   15
  32.       UseMaskColor    =   -1  'True
  33.       Width           =   330
  34.    End
  35.    Begin VB.CommandButton cmdTopToBottom 
  36.       Height          =   330
  37.       Left            =   705
  38.       Picture         =   "TabOrder.dox":0204
  39.       Style           =   1  'Graphical
  40.       TabIndex        =   3
  41.       ToolTipText     =   "102"
  42.       Top             =   15
  43.       UseMaskColor    =   -1  'True
  44.       Width           =   330
  45.    End
  46.    Begin VB.CommandButton cmdDown 
  47.       Height          =   330
  48.       Left            =   375
  49.       Picture         =   "TabOrder.dox":0306
  50.       Style           =   1  'Graphical
  51.       TabIndex        =   2
  52.       ToolTipText     =   "104"
  53.       Top             =   15
  54.       UseMaskColor    =   -1  'True
  55.       Width           =   330
  56.    End
  57.    Begin VB.CommandButton cmdUp 
  58.       Height          =   330
  59.       Left            =   45
  60.       Picture         =   "TabOrder.dox":0408
  61.       Style           =   1  'Graphical
  62.       TabIndex        =   1
  63.       ToolTipText     =   "102"
  64.       Top             =   15
  65.       UseMaskColor    =   -1  'True
  66.       Width           =   330
  67.    End
  68.    Begin VB.CommandButton cmdApply 
  69.       Height          =   330
  70.       Left            =   1695
  71.       Picture         =   "TabOrder.dox":050A
  72.       Style           =   1  'Graphical
  73.       TabIndex        =   6
  74.       Top             =   15
  75.       UseMaskColor    =   -1  'True
  76.       Width           =   330
  77.    End
  78.    Begin VB.ListBox lstTabIndex 
  79.       DragIcon        =   "TabOrder.dox":060C
  80.       Height          =   285
  81.       IntegralHeight  =   0   'False
  82.       Left            =   30
  83.       TabIndex        =   0
  84.       Top             =   360
  85.       Width           =   2025
  86.    End
  87. Attribute VB_Name = "docTabOrder"
  88. Attribute VB_GlobalNameSpace = False
  89. Attribute VB_Creatable = True
  90. Attribute VB_PredeclaredId = False
  91. Attribute VB_Exposed = True
  92. Option Explicit
  93. Dim mcmpCurrentForm As VBComponent      'current form
  94. Dim mcolCtls        As VBControls       'form's controls
  95. 'refresh types
  96. Const NEWFORM = 0
  97. Const TOPTOBOTTOM = 1
  98. Const LEFTTORIGHT = 2
  99. Const REFRESHCTLS = 3
  100. '================================================
  101. ' this sub sets the new tab order for all
  102. ' of the controls on te current form
  103. ' based on their order in the listbox
  104. '================================================
  105. Private Sub cmdApply_Click()
  106.   On Error GoTo cmdApply_ClickErr
  107.   Dim i As Integer
  108.   Dim sTmp As String
  109.   Dim nCtlArrIndex As Integer
  110.   If InRunMode(gVBInstance) Then Exit Sub
  111.   Screen.MousePointer = vbHourglass
  112.   For i = 0 To lstTabIndex.ListCount - 1
  113.     GetNameAndIndex lstTabIndex.List(i), sTmp, nCtlArrIndex
  114.     If nCtlArrIndex >= 0 Then
  115.       'set the new tab index
  116.       mcmpCurrentForm.Designer.VBControls.Item(sTmp, nCtlArrIndex).Properties!TabIndex = i
  117.     Else
  118.       'set the new tab index
  119.       mcmpCurrentForm.Designer.VBControls.Item(sTmp).Properties!TabIndex = i
  120.     End If
  121.   Next
  122.   Screen.MousePointer = vbDefault
  123.   Exit Sub
  124. cmdApply_ClickErr:
  125.   If MsgBox(Err.Description & vbCrLf & "Resume?", vbYesNo) = vbYes Then
  126.     Resume Next
  127.   End If
  128.   Screen.MousePointer = vbDefault
  129. End Sub
  130. Private Sub cmdLeftToRight_Click()
  131.   RefreshList LEFTTORIGHT
  132. End Sub
  133. Private Sub cmdTopToBottom_Click()
  134.   RefreshList TOPTOBOTTOM
  135. End Sub
  136. Private Sub cmdRefresh_Click()
  137.   RefreshList REFRESHCTLS
  138. End Sub
  139. Private Sub UserDocument_Show()
  140.   'load the strings from the resource file
  141.   cmdUp.ToolTipText = LoadResString(100)
  142.   cmdDown.ToolTipText = LoadResString(101)
  143.   cmdTopToBottom.ToolTipText = LoadResString(102)
  144.   cmdLeftToRight.ToolTipText = LoadResString(103)
  145.   cmdRefresh.ToolTipText = LoadResString(104)
  146.   cmdApply.ToolTipText = LoadResString(105)
  147. End Sub
  148. Private Sub UserDocument_Resize()
  149.   lstTabIndex.Width = ScaleWidth - (lstTabIndex.Left * 2)
  150.   lstTabIndex.Height = ScaleHeight - (cmdApply.Height + 100)
  151. End Sub
  152. 'this sub moves the dragged item to a new location
  153. 'based on the Y coordinate where it was dropped
  154. Private Sub lstTabIndex_DragDrop(Source As Control, x As Single, Y As Single)
  155.   Dim sTmp As String
  156.   Dim nListIndex As Integer
  157.   Dim nPos As Integer
  158.   Dim i As Integer
  159.   With lstTabIndex
  160.     nListIndex = .ListIndex
  161.     If Source = lstTabIndex Then
  162.       If nListIndex >= 0 Then
  163.         sTmp = .Text
  164.         nPos = (Y \ TextHeight(sTmp)) + .TopIndex
  165.         'check for the last item
  166.         If nPos > .ListCount Then
  167.           nPos = .ListCount
  168.         End If
  169.         .AddItem sTmp, nPos
  170.         If nListIndex > nPos Then
  171.           .RemoveItem nListIndex + 1
  172.         Else
  173.           .RemoveItem nListIndex
  174.         End If
  175.       End If
  176.     End If
  177.   End With
  178. End Sub
  179. Sub lstTabIndex_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
  180.   If Button = vbLeftButton Then lstTabIndex.Drag
  181. End Sub
  182. Private Sub cmdUp_Click()
  183.   On Error Resume Next
  184.   Dim nItem As Integer
  185.   With lstTabIndex
  186.     If .ListIndex < 0 Then Exit Sub
  187.     nItem = .ListIndex
  188.     If nItem = 0 Then Exit Sub  'can't move 1st item up
  189.     'move item up
  190.     .AddItem .Text, nItem - 1
  191.     'remove old item
  192.     .RemoveItem nItem + 1
  193.     'select the item that was just moved
  194.     .Selected(nItem - 1) = True
  195.   End With
  196. End Sub
  197. Private Sub cmdDown_Click()
  198.   On Error Resume Next
  199.   Dim nItem As Integer
  200.   With lstTabIndex
  201.     If .ListIndex < 0 Then Exit Sub
  202.     nItem = .ListIndex
  203.     If nItem = .ListCount - 1 Then Exit Sub 'can't move last item down
  204.     'move item down
  205.     .AddItem .Text, nItem + 2
  206.     'remove old item
  207.     .RemoveItem nItem
  208.     'select the item that was just moved
  209.     .Selected(nItem + 1) = True
  210.   End With
  211. End Sub
  212. '======================================================
  213. 'this function returns a value to put in the listbox
  214. 'for a control. It appends the Caption property
  215. 'if it exists and is not null. It also appends
  216. 'the control array index if the control is a
  217. 'member of a control array
  218. '======================================================
  219. Function ControlName(ctl As VBIDE.VBControl) As String
  220.   On Error Resume Next
  221.   Dim sTmp As String
  222.   Dim sCaption As String
  223.   Dim i As Integer
  224.   sTmp = ctl.Properties!Name
  225.   sCaption = ctl.Properties!Caption
  226.   'will be null if there isn't one
  227.   i = ctl.Properties!Index
  228.   If i >= 0 Then
  229.     sTmp = sTmp & "(" & i & ")"
  230.   End If
  231.   If Len(sCaption) > 0 Then
  232.     ControlName = sTmp & " - '" & sCaption & "'"
  233.   Else
  234.     ControlName = sTmp
  235.   End If
  236.   Err.Clear
  237. End Function
  238. '======================================================
  239. 'this sub rebuilds the list from the form's controls
  240. '======================================================
  241. Public Sub RefreshList(nType As Integer)
  242.   On Error GoTo RefreshListErr
  243.   Dim i As Integer
  244.   Dim ctl As VBControl
  245.   Dim sTmp As String
  246.   Dim ti As Integer
  247.   Dim sCtlName As String
  248.   Dim nCtlArrIndex As Integer
  249.   If InRunMode(gVBInstance) Then Exit Sub
  250.   'clear the list control
  251.   lstTabIndex.Clear
  252.   If gVBInstance.ActiveVBProject Is Nothing Then Exit Sub
  253.   If nType = NEWFORM Then
  254.     If mcmpCurrentForm Is gVBInstance.SelectedVBComponent Then
  255.       'same one as we have now
  256.       Exit Sub
  257.     End If
  258.   End If
  259.   'load the component
  260.   Set mcmpCurrentForm = gVBInstance.SelectedVBComponent
  261.   'check to see if we have a valid component
  262.   If mcmpCurrentForm Is Nothing Then
  263.     Exit Sub
  264.   End If
  265.   'make sure the active component is a form, user control or property page
  266.   If (mcmpCurrentForm.Type <> vbext_ct_VBForm) And _
  267.      (mcmpCurrentForm.Type <> vbext_ct_UserControl) And _
  268.      (mcmpCurrentForm.Type <> vbext_ct_DocObject) And _
  269.      (mcmpCurrentForm.Type <> vbext_ct_PropPage) Then
  270.     Exit Sub
  271.   End If
  272.   Set mcolCtls = mcmpCurrentForm.Designer.VBControls
  273. '  hWindow.Caption = mcmpCurrentForm.Name & " - " & LoadResString(10)
  274.   For Each ctl In mcmpCurrentForm.Designer.VBControls
  275.     'try to get the tabindex
  276.     On Error Resume Next
  277.     ti = ctl.Properties!TabIndex
  278.     If Err Then
  279.       'doesn't have a tabindex
  280.       Err.Clear
  281.       GoTo SkipIt
  282.     End If
  283.     On Error GoTo RefreshListErr
  284.     sTmp = ControlName(ctl)
  285.     'find out where it goes in the list
  286.     Select Case nType
  287.       Case NEWFORM, REFRESHCTLS
  288.         For i = 0 To lstTabIndex.ListCount - 1
  289.           If ti < lstTabIndex.ItemData(i) Then
  290.             Exit For
  291.           End If
  292.         Next
  293.         
  294.       Case TOPTOBOTTOM
  295.         'rearrange from top to bottom
  296.         For i = lstTabIndex.ListCount To 1 Step -1
  297.           GetNameAndIndex lstTabIndex.List(i - 1), sCtlName, nCtlArrIndex
  298.           If nCtlArrIndex >= 0 Then
  299.             'control array member
  300.             If ctl.Properties!Top > mcolCtls(sCtlName, nCtlArrIndex).Properties!Top Then
  301.               'it is above the current list item
  302.               Exit For
  303.             ElseIf ctl.Properties!Top = mcolCtls(sCtlName, nCtlArrIndex).Properties!Top Then
  304.               'it is at the same top position so see if it is farther left
  305.               If ctl.Properties!Left > mcolCtls(sCtlName, nCtlArrIndex).Properties!Left Then
  306.                 Exit For
  307.               End If
  308.             End If
  309.           Else
  310.             If ctl.Properties!Top > mcolCtls(sCtlName).Properties!Top Then
  311.               Exit For
  312.             ElseIf ctl.Properties!Top = mcolCtls(sCtlName).Properties!Top Then
  313.               If ctl.Properties!Left > mcolCtls(sCtlName).Properties!Left Then
  314.                 Exit For
  315.               End If
  316.             End If
  317.           End If
  318.         Next
  319.       
  320.       Case LEFTTORIGHT
  321.         'rearrange from left to right
  322.         For i = lstTabIndex.ListCount To 1 Step -1
  323.           GetNameAndIndex lstTabIndex.List(i - 1), sCtlName, nCtlArrIndex
  324.           If nCtlArrIndex >= 0 Then
  325.             'control array member
  326.             If ctl.Properties!Left > mcolCtls(sCtlName, nCtlArrIndex).Properties!Left Then
  327.               Exit For
  328.             ElseIf ctl.Properties!Left = mcolCtls(sCtlName, nCtlArrIndex).Properties!Left Then
  329.               If ctl.Properties!Top > mcolCtls(sCtlName, nCtlArrIndex).Properties!Top Then
  330.                 Exit For
  331.               End If
  332.             End If
  333.           Else
  334.             If ctl.Properties!Left > mcolCtls(sCtlName).Properties!Left Then
  335.               Exit For
  336.             ElseIf ctl.Properties!Left = mcolCtls(sCtlName).Properties!Left Then
  337.               If ctl.Properties!Top > mcolCtls(sCtlName).Properties!Top Then
  338.                 Exit For
  339.               End If
  340.             End If
  341.           End If
  342.         Next
  343.       
  344.     End Select
  345.     'add it to the list
  346.     lstTabIndex.AddItem sTmp, i
  347.     lstTabIndex.ItemData(lstTabIndex.NewIndex) = ti
  348.     lstTabIndex.Refresh
  349. SkipIt:
  350.   Next
  351.   Exit Sub
  352. RefreshListErr:
  353.   MsgBox Err.Description
  354. End Sub
  355. '======================================================
  356. 'this sub is called when a control gets removed
  357. '======================================================
  358. Public Sub ControlRemoved(ctl As VBControl)
  359.   Dim sTmp As String
  360.   Dim i As Integer
  361.   sTmp = ControlName(ctl)
  362.   For i = 0 To lstTabIndex.ListCount - 1
  363.     If lstTabIndex.List(i) = sTmp Then
  364.       'remove it from the list
  365.       lstTabIndex.RemoveItem i
  366.       Exit Sub
  367.     End If
  368.   Next
  369. End Sub
  370. '======================================================
  371. 'this sub is called when a control gets added
  372. '======================================================
  373. Public Sub ControlAdded(ctl As VBControl)
  374.   Dim i As Integer
  375.   'try to get the tabindex
  376.   On Error Resume Next
  377.   i = ctl.Properties!TabIndex
  378.   If Err Then
  379.     Err.Clear
  380.     'doesn't have a tabindex
  381.     Exit Sub
  382.   End If
  383.   lstTabIndex.AddItem ControlName(ctl)
  384. End Sub
  385. '======================================================
  386. 'this sub is called when a control gets renamed
  387. '======================================================
  388. Public Sub ControlRenamed(ctl As VBControl, sOldName As String, lOldIndex As Long)
  389.   On Error Resume Next
  390.   Dim sTmp As String
  391.   Dim i As Integer
  392.   If lOldIndex >= 0 Then
  393.     sOldName = sOldName & "(" & lOldIndex & ")"
  394.   End If
  395.   sTmp = ControlName(ctl)
  396.   For i = 0 To lstTabIndex.ListCount - 1
  397.     If Left$(lstTabIndex.List(i), Len(sOldName)) = sOldName Then
  398.       'remove it from the list
  399.       lstTabIndex.RemoveItem i
  400.       'add it back with the new name
  401.       lstTabIndex.AddItem sTmp, i
  402.       Exit Sub
  403.     End If
  404.   Next
  405.   Err.Clear
  406. End Sub
  407. Private Sub UserDocument_KeyDown(KeyCode As Integer, Shift As Integer)
  408.   'pass the keystrokes onto the IDE
  409.   HandleKeyDown Me, KeyCode, Shift
  410. End Sub
  411. '======================================================
  412. 'this sub extracts the control name and index
  413. 'from the formatted list item
  414. '======================================================
  415. Sub GetNameAndIndex(sListItem As String, sName As String, nIndex As Integer)
  416.   Dim nPos As Integer
  417.   Dim nPos2 As Integer
  418.   Dim sTmp As String
  419.   'strip off the caption if there is one
  420.   nPos = InStr(sListItem, " ")
  421.   If nPos > 0 Then
  422.     sTmp = Left$(sListItem, nPos - 1)
  423.   Else
  424.     sTmp = sListItem
  425.   End If
  426.   'now check for an index
  427.   nPos = InStr(sTmp, "(")
  428.   If nPos > 0 Then
  429.     'control has an index so we need to
  430.     'strip it off and save it
  431.     nPos2 = InStr(sTmp, ")")
  432.     nIndex = Val(Mid$(sTmp, nPos + 1, nPos2 - nPos))
  433.     sName = Left$(sTmp, nPos - 1)
  434.   Else
  435.     nIndex = -1
  436.     sName = sTmp
  437.   End If
  438. End Sub
  439.